/** 封装文章的接口 */
import axios from '@/utils/request'
/**
 * 获取文章推荐新闻的请求
 * @param {*} id
 * @param {*} timestamp
 * @returns
 */
export const getArticle = (id, timestamp) => {
  return axios({
    url: '/v1_0/articles',
    params: {
      channel_id: id,
      timestamp
    }
  })
}
/**
 * 对文章不喜欢
 * @param {*} target
 * @returns
 */
export const disLikeArt = target => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })
}
/**
 * 举报文章
 * @param {*} target 文章的id
 * @param {*} type 文章举报的类型
 * @returns
 */
export function reportArt(target, type) {
  return axios({
    method: 'post',
    url: '/v1_0/article/reports',
    data: {
      target,
      type
    }
  })
}
/**
 * 获取新闻详情
 * @param {*} id 文章id
 * @returns
 */
export const getSearchArticle = id => {
  return axios({
    url: `/v1_0/articles/${id}`
  })
}
/**
 * 对文章点赞
 * @param {*} target 文章的id
 * @returns
 */
export const addZan = target => {
  return axios({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target
    }
  })
}
/** 取消对文章点赞
 *
 * @param {*} target 文章的id
 * @returns
 */
export const delZan = target => {
  return axios({
    method: 'DELETE',
    url: `/v1_0/article/likings/${target}`
  })
}
/**
 * 对文章不喜欢
 * @param {*} target 文章id
 * @returns
 */
export const disLike = target => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })
}
/**
 * 取消对文章不喜欢

 * @param {*} target 文章id
 * @returns
 */
export const addLike = target => {
  return axios({
    method: 'DELETE',
    url: `/v1_0/article/dislikes/${target}`
  })
}

/**
 * 获取评论
 * @param {*} source 文章id
 * @param {*} offset
 * @returns
 */
export const getCommentArticle = (source, offset) => {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'a', // a-对文章(article)的评论
      source,
      offset
    }
  })
}
/**
 * 对文章或者评论进行评论
 * @param {*} target 评论的目标id
 * @param {*} content 评论内容
 * @returns
 */
export const addCommentArticle = (target, content) => {
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target,
      content
    }
  })
}
/**
 * 对评论或评论回复点赞
 * @param {*} target 点赞的评论id
 * @returns
 */
export const addLikeComment = target => {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target
    }
  })
}
/**
 * 取消对评论或评论回复点赞
 * @param {*} target 要取消点赞的评论id或评论回复id
 * @returns
 */
export const delLikeComment = target => {
  return axios({
    url: `/v1_0/comment/likings/${target}`,
    method: 'DELETE'
  })
}
/**
 *  获取 回复评论的数据
 * @param {*} source 评论id
 * @param {*} offset
 * @returns
 */
export const getCommentReply = (source, offset) => {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'c', // a-对文章(article)的评论
      source,
      offset,
      limit: 10
    }
  })
}
/**
 * 对评论进行回复评论
 * @param {*} artId 文章id
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @returns
 */
export const addCommentToComment = (artId, target, content) => {
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      art_id: artId,
      target,
      content
    }
  })
}
